package zuidzy

import (
	"extractor/core/common"
	"fmt"
	"os"
	"path"
)

func NewFilePipeline() *FilePipeline {
	file, err := os.Create(path.Join("data.txt"))
	if err != nil {
		panic(err.Error())
	}
	return &FilePipeline{
		file: file,
	}
}

type FilePipeline struct {
	file *os.File
}

func (f *FilePipeline) Process(items *common.PageItems) {

	if nil == items.GetItem("name") {
		return
	}

	//_ = db.AddVideo(&db.Video{
	//	0,
	//	fmt.Sprintf("%s", items.GetItem("name")),
	//	fmt.Sprintf("%s", items.GetItem("pic")),
	//	fmt.Sprintf("%s", items.GetItem("dd-value")),
	//	fmt.Sprintf("%s", items.GetItem("year")),
	//	fmt.Sprintf("%s", items.GetItem("director")),
	//	fmt.Sprintf("%s", items.GetItem("actor")),
	//	fmt.Sprintf("%s", items.GetItem("type")),
	//	fmt.Sprintf("%s", items.GetItem("des")),
	//	fmt.Sprintf("%s", items.GetItem("last")),
	//})

	_, _ = f.file.WriteString(fmt.Sprintf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
		items.GetItem("name"),
		items.GetItem("last"),
		items.GetItem("type"),
		items.GetItem("pic"),
		items.GetItem("year"),
		items.GetItem("actor"),
		items.GetItem("director"),
		items.GetItem("des"),
		items.GetItem("actor"),
		items.GetItem("dd-type"),
		items.GetItem("dd-value")))
}
